package carnet;

public class ToXML implements Visitor{
	String xml;
	public ToXML(){
		xml = new String();
	}
	
	@Override
	public void visitCarnet(Carnet c){
		xml += "\t<Carnet type=\""+ c.type +"\"> \n";
		for(Contact ct : c.getContacts()){
			ct.accept(this);
			xml += "\n";
		}
		xml += "\t<Carnet>";
	}
	
	@Override
	public void visitContact(Contact c) {
		xml += "\t\t<Contact " + c.getNom().getNom() + "=\"" + c.getNom().getValeur() +"\" ";
		xml += c.getPrenom().getNom() + "=\"" + c.getPrenom().getValeur() +"\" ";
		xml += c.getAdresse().getNom() + "=\"" + c.getAdresse().getValeur() +"\" ";
		xml += c.getTelephone().getNom() + "=\"" + c.getTelephone().getValeur() +"\" ";
		for(Champ ch : c.getAutresChamps()){
			ch.accept(this);
		}
		xml += ">";
		xml += "\t\t</Contact>";
	}
	
	@Override
	public void visitChamp(Champ c) {
		xml += c.getNom() + "=\"" + c.getValeur() +"\" ";
	}
}
